package c_leetcode.a_121_best_time_buy;

/**
 * 遍历
 * 时间复杂度    O(n^2)
 * 空间复杂度    O(1)
 * ------
 * LeetCode超时
 *
 * @author FRSF
 * @since 2025/3/5 22:02
 */
public class Foreach {
    public static void main(String[] args) {
        System.out.println(new Foreach().maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }

    public int maxProfit(int[] prices) {
        int max = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            for (int j = i + 1; j < prices.length; j++) {
                max = Math.max(max, prices[j] - prices[i]);
            }
        }
        return max;
    }
}
